package com.my.behaviourtype.stragety;

import java.util.Comparator;

public class Dog implements Comparable<Dog> {
	private int height;

	private int weight;

	public Dog(int height, int weight) {
		super();
		this.height = height;
		this.weight = weight;
	}

	public int getHeight() {
		return height;
	}

	public int getWeight() {
		return weight;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}
	@Override
	public String toString() {
		return "Dog [height=" + height + ", weight=" + weight + "]";
	}

	private Comparator<Dog> c;// 这样可以指定一个Comparator
	
	public Comparator<Dog> getC() {
		return c;
	}

	public void setC(Comparator<Dog> c) {
		this.c = c;
	}
	
	//给定一个比较策略
	@Override
	public int compareTo(Dog o) {
		if(c == null) {
			if(this.height > o.height) return 1;
			else if(this.height < o.height) return -1;
			return 0;
		}
		return c.compare(this, o);
	}

	
}
